package com.elder.business.service.impl;

import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

import com.alibaba.fastjson2.JSONObject;
import com.elder.business.domain.NurseContent;
import com.elder.common.core.domain.AjaxResult;
import com.elder.common.core.page.TableDataInfo;
import com.elder.common.utils.DateUtils;
import com.elder.common.utils.IntegerUtils;
import com.elder.common.utils.StringNewUtils;
import com.elder.common.utils.uuid.SnowGenerator;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.elder.business.mapper.FeedbackInfoMapper;
import com.elder.business.domain.FeedbackInfo;
import com.elder.business.service.IFeedbackInfoService;

/**
 * 反馈信息Service业务层处理
 * 
 * @author elder
 * @date 2023-11-26
 */
@Service
public class FeedbackInfoServiceImpl implements IFeedbackInfoService 
{
    @Autowired
    private FeedbackInfoMapper feedbackInfoMapper;

    /**
     * 查询反馈信息
     * 
     * @param feedbackId 反馈信息主键
     * @return 反馈信息
     */
    @Override
    public JSONObject selectFeedbackInfoByFeedbackId(Long feedbackId)
    {
        FeedbackInfo v = feedbackInfoMapper.selectFeedbackInfoByFeedbackId(feedbackId);
        JSONObject obj = new JSONObject();
        obj.put("feedbackId", StringNewUtils.formatStr(v.getFeedbackId()));
        obj.put("feedbackTitle", StringNewUtils.formatStr(v.getFeedbackTitle()));
        obj.put("feedbackType", StringNewUtils.formatStr(v.getFeedbackType()));
        obj.put("feedbackContent", StringNewUtils.formatStr(v.getFeedbackContent()));
        obj.put("feedbackPeople", StringNewUtils.formatStr(v.getFeedbackPeople()));
        obj.put("isDelete", StringNewUtils.formatStr(v.getIsDelete()));
        obj.put("isSolve", v.getIsSolve());
        obj.put("notes",v.getNotes());
        return obj;
    }

    /**
     * 查询反馈信息列表
     *
     * @return 反馈信息
     */
    @Override
    public TableDataInfo selectFeedbackInfoList(String feedbackTitle, Integer isSolve, Integer pageNum, Integer pageSize)
    {
        PageHelper.startPage(pageNum, pageSize);
        List<FeedbackInfo> list = feedbackInfoMapper.selectFeedbackInfoList(feedbackTitle, isSolve);
        PageInfo<FeedbackInfo> pageInfo = new PageInfo<>(list);
        List<FeedbackInfo> feedbackInfoList = pageInfo.getList();
        TableDataInfo dataInfo = new TableDataInfo();
        List<JSONObject> objectList = feedbackInfoList.stream().map(v -> {
            JSONObject obj = new JSONObject();
            obj.put("feedbackId", StringNewUtils.formatStr(v.getFeedbackId()));
            obj.put("feedbackTitle", StringNewUtils.formatStr(v.getFeedbackTitle()));
            obj.put("feedbackType", StringNewUtils.formatStr(v.getFeedbackType()));
            obj.put("feedbackContent", StringNewUtils.formatStr(v.getFeedbackContent()));
            obj.put("feedbackPeople", StringNewUtils.formatStr(v.getFeedbackPeople()));
            obj.put("isDelete", StringNewUtils.formatStr(v.getIsDelete()));
            obj.put("isSolve", v.getIsSolve());
            obj.put("notes",v.getNotes());
            return obj;
        }).collect(Collectors.toList());
        dataInfo.setRows(objectList);
        dataInfo.setCode(200);
        dataInfo.setTotal(pageInfo.getTotal());
        return dataInfo;
    }

    /**
     * 新增反馈信息
     * 
     * @param feedbackInfo 反馈信息
     * @return 结果
     */
    @Override
    public int insertFeedbackInfo(FeedbackInfo feedbackInfo)
    {
        feedbackInfo.setFeedbackId(SnowGenerator.getId());
        feedbackInfo.setCreateTime(DateUtils.getLongTime());
        feedbackInfo.setIsSolve(0);
        return feedbackInfoMapper.insertFeedbackInfo(feedbackInfo);
    }

    /**
     * 修改反馈信息
     * 
     * @param feedbackInfo 反馈信息
     * @return 结果
     */
    @Override
    public int updateFeedbackInfo(FeedbackInfo feedbackInfo)
    {
        return feedbackInfoMapper.updateFeedbackInfo(feedbackInfo);
    }

    /**
     * 批量删除反馈信息
     * 
     * @param feedbackIds 需要删除的反馈信息主键
     * @return 结果
     */
    @Override
    public int deleteFeedbackInfoByFeedbackIds(Long[] feedbackIds)
    {
        return feedbackInfoMapper.deleteFeedbackInfoByFeedbackIds(feedbackIds);
    }

    /**
     * 删除反馈信息信息
     * 
     * @param feedbackId 反馈信息主键
     * @return 结果
     */
    @Override
    public int deleteFeedbackInfoByFeedbackId(Long feedbackId)
    {
        return feedbackInfoMapper.deleteFeedbackInfoByFeedbackId(feedbackId);
    }

    @Override
    public JSONObject updateFeedbackInfoSolveStatus(Long feedbackId, String isSolve) {
        feedbackInfoMapper.updateFeedbackInfoSolveStatus(feedbackId, IntegerUtils.toInteger(isSolve),null);
        JSONObject obj = new JSONObject();
        obj.put("msg", "操作成功");
        obj.put("code", 200);
        return obj;
    }

    @Override
    public AjaxResult feedBackResultNotice(Long feedbackId, Integer isSolve, String notes) {
        feedbackInfoMapper.updateFeedbackInfoSolveStatus(feedbackId, isSolve,notes);
        return AjaxResult.success();
    }
}
